package com.spring.data.jpa.core;

import org.hibernate.cfg.ImprovedNamingStrategy;

public class MyNamingStrategy extends ImprovedNamingStrategy  {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String currentTablePrefix;
	protected String tabPre="T_";

	
	@Override
	/**
	 * Return the unqualified class name, mixed case converted to underscores
	 */
	
	public String classToTableName(String className) {
		 currentTablePrefix = className.toUpperCase() + "_";
		 
		return tabPre+tableName(className);
	}

	@Override
	public String columnName(String columnName) {
		 return addUnderscores(columnName).toUpperCase();
	}

	@Override
	public String propertyToColumnName(String propertyName) {
//		 if(propertyName.equals("id")){
//			 return currentTablePrefix + addUnderscores(propertyName).toUpperCase();
//		 }else{
//			 return addUnderscores(propertyName).toUpperCase();
//		 }
		 //return (propertyName.equals("id")?currentTablePrefix:"")+addUnderscores(propertyName).toUpperCase();
		return addUnderscores(propertyName).toUpperCase();
	}

	@Override
	public String tableName(String tableName) {
		 return addUnderscores(tableName).toUpperCase();
	}

	@Override
	public String logicalColumnName(String columnName, String propertyName) {
		return super.logicalColumnName(columnName, propertyName);
	}

}
